// 压缩图片
function compressImage(imgSrc, getSrc) {
    var src;
    var img = new Image();
    img.src = imgSrc;
    img.crossOrigin = "Anonymous";
    img.onload = function () {
        var canvas = document.createElement('canvas');
        var context = canvas.getContext('2d');
        canvas.width = 50;
        canvas.height = 50;
        context.drawImage(img, 0, 0, 50, 50);
        var url = canvas.toDataURL("image/jpeg");
        var blob = dataURLtoBlob(url);
        src = URL.createObjectURL(blob);
        getSrc(src);
    }
}

// base64转blob
function dataURLtoBlob(dataurl) {
    var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
        bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
    while (n--) {
        u8arr[n] = bstr.charCodeAt(n);
    }
    return new Blob([u8arr], { type: mime });
}